home *** CD-ROM | disk | FTP | other *** search
- Path: lrz-muenchen.de!news
- From: watzka@stat.uni-muenchen.de (Kurt Watzka)
- Newsgroups: comp.lang.c
- Subject: Re: #include "" for large programs.
- Date: 14 Apr 1996 22:39:57 GMT
- Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
- Distribution: world
- Message-ID: <4krurt$fat@sparcserver.lrz-muenchen.de>
- References: <Pine.SUN.3.92.960411195730.24973A-100000@suntan> <4krrmi$7ef@mother.usf.edu>
- NNTP-Posting-Host: sun2.lrz-muenchen.de
-
- gohel@csee.usf.edu (Himanshu Gohel) writes:
-
- >In article <Pine.SUN.3.92.960411195730.24973A-100000@suntan>, "Carlos Diaz (CS)" <cdiaz@eng.usf.edu> writes:
-
- >The way to avoid multiple definitions (and similarly multiple inclusions
- >of .h files) is to do the following:
-
- >#ifndef __MYHEADERFILE__
- >#define __MYHEADERFILE__
- > ...all your header file stuff here...
- >#endif
-
- Change this to something not using macro names starting with a
- double underscore and an upper case letter and I will happily
- agree with you.
-
- >Now you can include this .h file as many times as you want and you
- >won't have problems with multiple defintions because of the #ifndef.
-
- There also is a non zero chance that the stuff defined in the
- header file will be underfined in your compilation module that
- includes such a header.
-
- >Also, there is a place for the const keyword, but in C that cannot
- >be put in a .h file. It has to go in a C file.
-
- Try something like
-
- #if defined(GLOBALS)
- #define GLOBAL
- #else
- #define GLOBAL extern
- #endif
-
- GLOBAL const answer
- #if defined(GLOBALS)
- = 42;
- #else
- ;
- #endif
-
- Be sure to define "GLOBALS" in exactly one compilation unit that includes
- a header file with that construct.
-
- Kurt
- --
- | Kurt Watzka Phone : +49-89-2180-6254
- | watzka@stat.uni-muenchen.de
-